package net.bingosoft.common.data.security;


/**
 * 2008-4-22 下午06:52:48
 * Author:yangdongyu(yangdy@bingosoft.net)
 * ReadMe:数据安全上下文,用于查找动作对应的规则,并依据对应ISecurityRuleParser完成对应的解析
 * ChangeLog:
 */
public class DataSecurityContext {
	
	private ISecurityRuleLocator ruleLocator;	
	private ISecurityRuleParser ruleParser;
	
	public ISecurityRuleLocator getRuleLocator() {
		return ruleLocator;
	}

	public void setRuleLocator(ISecurityRuleLocator ruleLocator) {
		this.ruleLocator = ruleLocator;
	}

	public ISecurityRuleParser getRuleParser() {
		return ruleParser;
	}

	public void setRuleParser(ISecurityRuleParser parser) {
		this.ruleParser = parser;
	}	
	
    

	/**
     * 查找动作对应的规则,并实现规则的解析
     * @param action 动作的名称
     * @return 和动作对应,并完成解析的规则
     */
	public Object resolve(String action){
		String rule = null;
		if(this.ruleLocator != null){
			rule = ruleLocator.locate(action);
		}
		if(rule != null && this.ruleParser != null){
			rule = this.ruleParser.parseRule(rule);
		}
		return rule;
	}

}
